<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        // 复数属性设置对象 - 多个属性可以一起添加
        // 参数1 ：创建对象本身
        // 参数2：属性说明
        function newObj() {
            var val = '男';
           return Object.defineProperties({
                age: 18
            }, {
                name: {
                    value: "老王",
                    writable: true,
                    configurable: true,
                    enumerable: true
                },
                sex: {
                    get: function () {
                        return val;
                    },
                    set: function (v) {
                        val = v;
                    }
                }
            });
        }

        var obj = newObj();

        obj.sex = '女';

        console.log(obj);

    </script>
</body>

</html>